package logic

import (
	"2210a/commod/commodrpc/commodrpc"
	"2210a/commod/pkg"
	"context"

	"2210a/commod/commodapi/internal/svc"
	"2210a/commod/commodapi/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type SendSmsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewSendSmsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendSmsLogic {
	return &SendSmsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *SendSmsLogic) SendSms(req *types.SendSmsRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	sms, err := l.svcCtx.CommodEpc.SendSms(l.ctx, &commodrpc.SendSmsRequest{
		Username: req.Username,
		Source:   req.Source,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: pkg.Trl(err.Error()),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "短信发送成功",
		Data:    sms,
	}, nil
}
